OpenRoads Designer CONNECT Edition SDK Help

Report missing feature definition for the point and components

The below code loads the template library and gets the current active template. It iterates the points and components from the active template. For points the style name is used to get the feature definition, for component material name is used. It then finds the point and component having missing feature definition.


//Required References
using Bentley.CifNET.GeometryModel.SDK;
using System.Diagnostics;
using Bentley.CifNET.ContentManagementModel;

 public void ReportMissingFeatureDefinitionForPointsAndComponents()
        {
            //Get default template library path
            string strTemplateLibraryPath = Bentley.CifNET.GeometryModel.SDK.TemplateLibrary.GetDefaultTemplateLibraryPath();

            //Load template library
            Bentley.CifNET.GeometryModel.SDK.TemplateLibrary templateLibary = Bentley.CifNET.GeometryModel.SDK.TemplateLibrary.Load(strTemplateLibraryPath);

            //Get active template from template library
            TemplateDefinition templateDefinition = templateLibary.ActiveTemplate;

            //Get ObjectSpace and CivilModel to get object settings 
            Bentley.CifNET.CadSystem.IObjectSpaceManager objectSpaceManager = Bentley.CifNET.ServiceManager.Instance.GetService<Bentley.CifNET.CadSystem.IObjectSpaceManager>();
            if (objectSpaceManager == null) return;
            Bentley.CifNET.Objects.IObjectSpace objectSpace = objectSpaceManager.ObjectSpace;
            if (objectSpace == null) return;
            Bentley.CifNET.Model.CivilModel civilModel = Bentley.CifNET.Model.CivilModel.GetCivilModel(objectSpace, Bentley.CifNET.Model.GetModelOptions.CheckIfExist);
            if (civilModel == null) return;


            //Report points having no feature definition from current template
            for (int itr = 0; itr < templateDefinition.PointCount; itr++)
            {
                TemplatePoint point = templateDefinition.GetPointAt(itr);

                ObjectSettings featureDefinition;
                string styleName = point.StylePath + point.StyleName;
                ContentManagementModel.TryGetObjectSettingsByName(objectSpace, civilModel, styleName, out featureDefinition);

                //If objectSettings is null then point has missing feature definition
                if (featureDefinition == null)
                {
                     Trace.WriteLine("Point has missing feature definition, Point name: " + point.Name);
                }
            }

            //Report components having no feature definition from current template
            for (int itr = 0; itr < templateDefinition.ComponentCount; itr++)
            {
                TemplateComponent component = templateDefinition.GetComponentAt(itr);

                ObjectSettings featureDefinition;
                string materialName = component.MaterialPath + component.MaterialName;
                ContentManagementModel.TryGetObjectSettingsByName(objectSpace, civilModel, materialName, out featureDefinition);

                //If objectSettings is null then point has missing feature definition
                if (featureDefinition == null)
                {
                    Trace.WriteLine("Component has missing feature definition, Component name: " + component.ComponentName);
                }
            }
        }